package com.ruoyi.dash.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dash.domain.TbHighStandardFarmland;
import com.ruoyi.dash.service.ITbHighStandardFarmlandService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 高标准农田Controller
 * 
 * @author ruoyi
 * @date 2025-10-24
 */
@RestController
@RequestMapping("/dash/farmland")
public class TbHighStandardFarmlandController extends BaseController
{
    @Autowired
    private ITbHighStandardFarmlandService tbHighStandardFarmlandService;

    /**
     * 查询高标准农田列表
     */
    @PreAuthorize("@ss.hasPermi('dash:farmland:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbHighStandardFarmland tbHighStandardFarmland)
    {
        startPage();
        List<TbHighStandardFarmland> list = tbHighStandardFarmlandService.selectTbHighStandardFarmlandList(tbHighStandardFarmland);
        return getDataTable(list);
    }

    /**
     * 导出高标准农田列表
     */
    @PreAuthorize("@ss.hasPermi('dash:farmland:export')")
    @Log(title = "高标准农田", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbHighStandardFarmland tbHighStandardFarmland)
    {
        List<TbHighStandardFarmland> list = tbHighStandardFarmlandService.selectTbHighStandardFarmlandList(tbHighStandardFarmland);
        ExcelUtil<TbHighStandardFarmland> util = new ExcelUtil<TbHighStandardFarmland>(TbHighStandardFarmland.class);
        util.exportExcel(response, list, "高标准农田数据");
    }

    /**
     * 获取高标准农田详细信息
     */
    @PreAuthorize("@ss.hasPermi('dash:farmland:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tbHighStandardFarmlandService.selectTbHighStandardFarmlandById(id));
    }

    /**
     * 新增高标准农田
     */
    @PreAuthorize("@ss.hasPermi('dash:farmland:add')")
    @Log(title = "高标准农田", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbHighStandardFarmland tbHighStandardFarmland)
    {
        return toAjax(tbHighStandardFarmlandService.insertTbHighStandardFarmland(tbHighStandardFarmland));
    }

    /**
     * 修改高标准农田
     */
    @PreAuthorize("@ss.hasPermi('dash:farmland:edit')")
    @Log(title = "高标准农田", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbHighStandardFarmland tbHighStandardFarmland)
    {
        return toAjax(tbHighStandardFarmlandService.updateTbHighStandardFarmland(tbHighStandardFarmland));
    }

    /**
     * 删除高标准农田
     */
    @PreAuthorize("@ss.hasPermi('dash:farmland:remove')")
    @Log(title = "高标准农田", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tbHighStandardFarmlandService.deleteTbHighStandardFarmlandByIds(ids));
    }
}
